package com.ljh.redis.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @author: Themberfue
 * @date: 2025/4/5 15:38
 * @description:
 */
@RestController
public class SetController {
    @Autowired
    StringRedisTemplate redisTemplate;

    @GetMapping("/set")
    public Set<String> set() {
        redisTemplate.execute((RedisConnection connection) -> {
            connection.flushAll();
            return null;
        });

        redisTemplate.opsForSet().add("k1", "111", "222", "333", "444");

        Long size = redisTemplate.opsForSet().size("k1");
        System.out.println("size:" + size);

        Boolean isMember = redisTemplate.opsForSet().isMember("k1", "222");
        System.out.println("isMember:" + isMember);

        Long remove = redisTemplate.opsForSet().remove("k1", "444");
        System.out.println("remove:" + remove);

        return redisTemplate.opsForSet().members("k1");
    }
}
